/**
 * Created by LeungZ on 2016/9/7.
 */
class Add {
    constructor(clusterSrv, $modalInstance, ctgNotification, edit) {
        "ngInject"
        this.formdata = {};
        if (edit) {
            this.formdata = {
                id: edit.id,
                name: edit.clusterName,
                code: edit.clusterCode,
                addr: edit.monitorUrl,
                tengineClusterCode: edit.tengineClusterCode
            }
        }
        this.action = "新增";
        if (this.formdata.id) {
            this.action = "修改";
        }
        this.cancel = function() {
            $modalInstance.dismiss('cancel');
        };
        this.save = () => {
            this.loading = true;
            clusterSrv.addCluster(this.formdata).then(data => {
                $modalInstance.close();

                ctgNotification.success(this.action + '容器集群 ' + this.formdata.name + ' 成功.');
            }).catch((data)=>{

                ctgNotification.error(this.action + '容器集群失败, ' + data.resultMsg);
            }).finally(() => {
                this.loading = false;
            });
        }
    }
}
export default Add